package cn.lg.soar.message.feign.fallback;

import cn.lg.soar.message.api.model.WebSocketDTO;
import cn.lg.soar.message.feign.WebSocketApiFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.message.client.WebSocketApiClient")
public class WebSocketApiFallbackFactory implements FallbackFactory<WebSocketApiFeign> {

    protected static final Logger LOGGER = LoggerFactory.getLogger(WebSocketApiFallbackFactory.class);

    @Override
    public WebSocketApiFeign create(Throwable cause) {
        return new WebSocketApiFeign() {
            @Override
            public void broadcast(String topic, String message) {
                LOGGER.error("broadcast：topic={}，message={}", topic, message, cause);
            }

            @Override
            public void sendMessage(String topic, WebSocketDTO dto) {
                LOGGER.error("sendMessage：topic={}，dto={}", topic, dto, cause);
            }
        };
    }
}
